package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	//api/album/category/findAllCategory1

	@Operation(summary = "获取所有的一级分类")
	@GetMapping("/findAllCategory1")
	public Result findAllCategory1(){
		//调用服务层
		List<BaseCategory1> list = baseCategoryService.list();
		//返回数据
		return Result.ok(list);
	}


	//http://localhost/api/album/category/findTopBaseCategory3/1
	/**
	 * 根据以及分类id获取三级分类名称
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据以及分类id获取三级分类名称")
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result findTopBaseCategory3(@PathVariable Long category1Id){
		//调用服务层方法
		List<BaseCategory3> category3List = baseCategoryService.findTopBaseCategory3(category1Id);
		//返回数据
		return Result.ok(category3List);
	}

	//http://localhost/api/album/category/getBaseCategoryList/{category1id}

	/**
	 * 根据以及分类id获取二三级分类信息
	 * @param category1id
	 * @return
	 */
	@Operation(summary = "根据以及分类id获取二三级分类信息")
	@GetMapping("/getBaseCategoryList/{category1id}")
	public Result getbaseCategoryList(@PathVariable Long category1id){
		//调用业务层方法
		 JSONObject categrotys = baseCategoryService.getbaseCategoryList(category1id);
		//返回结果
		return Result.ok(categrotys);
	}

	/**
	 * 根据三级分类id获取分类id
	 * @param categroy3Id
	 * @return
	 */
	@Operation(summary = "根据三级分类id获取分类id")
	@GetMapping("/getCategoryValue/{category3Id}")
	public Result<BaseCategoryView>  getCategoryValue(@PathVariable Long category3Id){
		//调用服务层方法
		BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
		//返回结果
		return Result.ok(baseCategoryView);
	}

	@Operation(summary = "分类管理")
	@GetMapping("/getBaseCategoryList")
	public Result<List<JSONObject>> getBaseCategoryList(){
		//返回一个json字符串列表
		//ArrayList<JSONObject> list = new ArrayList<>();
		//调用业务层接口
		List<JSONObject> list = baseCategoryService.getBaseCategoryList();
		return Result.ok(list);
	}

	@Operation(summary = "获取专辑的属性和对应的属性值")
	@GetMapping("/findAttribute/{category1Id}")
	public Result findAttribute(@PathVariable Long category1Id){
		//从服务层调用方法
		List<BaseAttribute> list = baseCategoryService.findAttribute(category1Id);
		System.out.println(list);
		//返回值
		return Result.ok(list);
	}


}

